home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / librw / RWDiskPageHeap.z / RWDiskPageHeap
Encoding:
Text File  |  1998-10-30  |  7.0 KB  |  199 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))                                      RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWDiskPageHeap - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/diskpage.h>
  13.  
  14.  
  15.  
  16.               unsigned nbufs;
  17.           unsigned pagesize;
  18.           RWDiskPageHeap heap("filename", nbufs, pagesize) ;
  19.  
  20.  
  21.  
  22.  
  23. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  24.      Class RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp is a specializing type of buffered page heap.  It
  25.      swaps its pages to disk as necessary.
  26.  
  27. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  28.      None
  29.  
  30. EEEExxxxaaaammmmpppplllleeee
  31.      In this example, 100 nodes of a linked list are created and strung
  32.      together.  The list is then walked, confirming that it contains 100
  33.      nodes.  Each node is a single page.  The "pointer" to the next node is
  34.      actually the handle for the next page.
  35.  
  36.               #include <rw/diskpage.h>
  37.  
  38.  
  39.  
  40.               #include <rw/rstream.h>
  41.           struct Node {
  42.             int key;
  43.             RWHandle     next;
  44.           };
  45.           RWHandle head = 0;
  46.           const int N = 100;  // Exercise 100 Nodes
  47.           main() {
  48.             // Construct a disk-based page heap with page size equal
  49.             // to the size of Node and with 10 buffers:
  50.             RWDiskPageHeap heap(0, 10, sizeof(Node));
  51.             // Build the linked list:
  52.             for (int i=0; i<N; i++){
  53.               RWHandle h = heap.allocate();
  54.               Node* newNode = (Node*)heap.lock(h);
  55.               newNode->key  = i;
  56.               newNode->next = head;
  57.               head = h;
  58.               heap.dirty(h);
  59.               heap.unlock(h);
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))                                      RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.             }
  75.           // Now walk the list:
  76.           unsigned count = 0;
  77.           RWHandle nodeHandle = head;
  78.           while(nodeHandle){
  79.           Node* node = (Node*)heap.lock(nodeHandle);
  80.           RWHandle nextHandle = node->next;
  81.           heap.unlock(nodeHandle);
  82.           heap.deallocate(nodeHandle);
  83.           nodeHandle = nextHandle;
  84.           count++;
  85.             }
  86.           cout << "List with " << count << " nodes walked.0;
  87.           return 0;
  88.           }
  89.  
  90.  
  91.      PPPPrrrrooooggggrrrraaaammmm oooouuuuttttppppuuuutttt::::
  92.  
  93.               List with 100 nodes walked.
  94.  
  95.  
  96.  
  97. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrr
  98.               RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp(const char* filename = 0,
  99.                          unsigned nbufs       = 10,
  100.                          unsigned pgsize      = 512);
  101.  
  102.  
  103.      Constructs a new disk-based page heap.  The heap will use a file with
  104.      filename ffffiiiilllleeeennnnaaaammmmeeee, otherwise it will negotiate with the operating system
  105.      for a temporary filename.  The number of buffers, each the size of the
  106.      page size, will be nnnnbbbbuuuuffffssss.  No more than this many pages can be locked at
  107.      any one time.  The size of each page is given by ppppggggssssiiiizzzzeeee.  To see whether
  108.      a valid RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp has been constructed, call member function
  109.      iiiissssVVVVaaaalllliiiidddd(((()))).
  110.  
  111. PPPPuuuubbbblllliiiicccc DDDDeeeessssttttrrrruuuuccccttttoooorrrr
  112.               virtual
  113.           ~RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp();
  114.  
  115.  
  116.      Returns any resources used by the disk page heap back to the operating
  117.      system.  All pages should have been deallocated before the destructor is
  118.      called.
  119.  
  120. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  121.               virtual RWHandle
  122.           aaaallllllllooooccccaaaatttteeee();
  123.  
  124.  
  125.      Redefined from class RRRRWWWWVVVViiiirrrrttttuuuuaaaallllPPPPaaaaggggeeeeHHHHeeeeaaaapppp.  Allocates a page off the disk
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))                                      RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.      page heap and returns a handle for it.  If there is no more space (for
  141.      example, the disk is full) then returns zero.
  142.  
  143.               virtual void
  144.           ddddeeeeaaaallllllllooooccccaaaatttteeee(RWHandle h);
  145.  
  146.  
  147.      Redefined from class RRRRWWWWBBBBuuuuffffffffeeeerrrreeeeddddPPPPaaaaggggeeeeHHHHeeeeaaaapppp.  Deallocate the page associated
  148.      with handle hhhh.  It is not an error to deallocate a zero handle.
  149.  
  150.               virtual void
  151.           ddddiiiirrrrttttyyyy(RWHandle h);
  152.  
  153.  
  154.      Inherited from RRRRWWWWBBBBuuuuffffffffeeeerrrreeeeddddPPPPaaaaggggeeeeHHHHeeeeaaaapppp.
  155.  
  156.               RWBoolean
  157.           iiiissssVVVVaaaalllliiiidddd() const;
  158.  
  159.  
  160.      Returns TTTTRRRRUUUUEEEE if this is a valid RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp.
  161.  
  162.               virtual void*
  163.           lllloooocccckkkk(RWHandle h);
  164.  
  165.  
  166.      Inherited from RRRRWWWWBBBBuuuuffffffffeeeerrrreeeeddddPPPPaaaaggggeeeeHHHHeeeeaaaapppp.
  167.  
  168.               virtual void
  169.           uuuunnnnlllloooocccckkkk(RWHandle h);
  170.  
  171.  
  172.      Inherited from RRRRWWWWBBBBuuuuffffffffeeeerrrreeeeddddPPPPaaaaggggeeeeHHHHeeeeaaaapppp.
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.